import { compareVersion } from "@/utils";
import { systemAppStore } from '@/stores/system'

export interface RIGHT_IDS {
  ONLINE: string;
  DICT: string;
  DOC: string;
  WORD: string;
  IMAGE: string;
  SCREENSHOT: string;
  PLAY: string;
}

export const getRightIds = () => {
  const verison = systemAppStore().appInfo.version
  if (compareVersion(verison, '1.0.0.4') <= 0) {
    return {
      ONLINE: import.meta.env.VITE_APP_ONLINE_RID_OLD as string,
      DICT: import.meta.env.VITE_APP_DICT_RID_OLD as string,
      DOC: import.meta.env.VITE_APP_DOC_RID_OLD as string,
      WORD: import.meta.env.VITE_APP_WORD_RID_OLD as string,
      IMAGE: import.meta.env.VITE_APP_IMAGE_RID_OLD as string,
      SCREENSHOT: import.meta.env.VITE_APP_SCREENSHOT_RID_OLD as string,
      PLAY: import.meta.env.VITE_APP_PLAY_RID_OLD as string
    }
  } else {
    return {
      ONLINE: import.meta.env.VITE_APP_ONLINE_RID as string,
      DICT: import.meta.env.VITE_APP_DICT_RID as string,
      DOC: import.meta.env.VITE_APP_DOC_RID as string,
      WORD: import.meta.env.VITE_APP_WORD_RID as string,
      IMAGE: import.meta.env.VITE_APP_IMAGE_RID as string,
      SCREENSHOT: import.meta.env.VITE_APP_SCREENSHOT_RID as string,
      PLAY: import.meta.env.VITE_APP_PLAY_RID as string
    }
  }
}

// export const RIGHT_IDS: RIGHT_IDS = {
//   ONLINE: import.meta.env.VITE_APP_ONLINE_RID as string,
//   DICT: import.meta.env.VITE_APP_DICT_RID as string,
//   DOC: import.meta.env.VITE_APP_DOC_RID as string,
//   WORD: import.meta.env.VITE_APP_WORD_RID as string,
//   IMAGE: import.meta.env.VITE_APP_IMAGE_RID as string,
//   SCREENSHOT: import.meta.env.VITE_APP_SCREENSHOT_RID as string,
//   PLAY: import.meta.env.VITE_APP_PLAY_RID as string
// };

export const getRightIdByType = (type: keyof RIGHT_IDS): string => {
  const RIGHT_IDS = getRightIds()
  return RIGHT_IDS[type];
};
